﻿using SqlSugar;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Api.Shared.Model.Common
{
    public class MyAlarm : INotifyPropertyChanged
    {
        private int id;

        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id
        {
            get => id;
            set { id = value; }
        }

        private string alarmId;
        [SugarColumn(IsNullable = true)]
        public string AlarmId
        {
            get => alarmId;
            set { alarmId = value; }
        }

        private string alarmMessage;
        [SugarColumn(IsNullable = true)]
        public string AlarmMessage
        {
            get => alarmMessage;
            set
            {
                if (alarmMessage != value)
                {
                    alarmMessage = value;
                    NotifyPropertyChanged();
                }
            }
        }

        private DateTime insertTime;
        [SugarColumn(IsNullable = true)]
        public DateTime InsertTime
        {
            get => insertTime;
            set { insertTime = value; }
        }

        private string alarmFull;
        [SugarColumn(IsNullable = true)]
        public string AlarmFull
        {
            get => alarmFull;
            set
            {
                alarmFull = value;
            }
        }
        /// <summary>
        /// 返回报警时间
        /// </summary>
        /// <param name="a">年</param>
        /// <param name="b">月</param>
        /// <param name="c">日</param>
        /// <param name="d">时</param>
        /// <param name="e">分</param>
        /// <param name="f">秒</param>
        /// <returns></returns>
        public string FuncAlarmFull(short a, short b, short c, short d, short e, short f)
        {
            string str =
            $"{a}年{b}月{c}日{d}:{e}:{f}";
            AlarmFull = str;
            return str;
        }
        /// <summary>
        /// 返回报警Id和报警信息
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string[] FuncAlarmIdMessage(string str)
        {
            if (str.Contains(' '))
            {
                string[] strArr = str.Split(new char[1] { ' ' });
                if (strArr[0] == null)
                {
                    this.AlarmId = "0";
                }
                else
                {
                    this.AlarmId = strArr[0];
                }
                this.AlarmMessage = strArr[0] + ":" + strArr[1];
                return strArr;
            }
            if (!str.Contains(' '))
            {
                this.AlarmId = "无";
                this.AlarmMessage = "无: " + str;
            }
            string[] strArr1 = { };

            return strArr1;
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
